package com.edu.compile.constant;

import com.edu.compile.template.NodeTemplateParse;
import com.edu.compile.template.ftl.block.Http;
import com.edu.compile.template.ftl.block.IfElse;
import com.edu.compile.template.ftl.block.Loop;
import com.edu.compile.template.ftl.block.LoopEnd;
import com.edu.compile.template.ftl.block.Switch;
import com.edu.compile.template.ftl.call.NodeCall;
import com.edu.compile.template.ftl.node.Calc;
import com.edu.compile.template.ftl.node.HttpResponse;
import com.edu.compile.template.ftl.node.Redis;
import com.edu.compile.template.ftl.node.TripartiteApi;

/**
 * @author yanzhao
 * @date 2021/10/19 23:10
 * @since 1.0.0
 */
public enum NodeTypeEnum implements Comparator {

    HTTP("http", Http.class),
    IF_ELSE("if_else", IfElse.class),
    SWITCH("switch", Switch.class),
    CALC("calc", Calc.class),
    NODE("node", NodeCall.class),
    LOOP("loop", Loop.class),
    LOOP_END("loop_end", LoopEnd.class),
    TRIPARTITE_API("tripartite_api", TripartiteApi.class),
    REDIS("redis", Redis.class),
    HTTP_RESPONSE("http_response", HttpResponse.class),
    ;

    public static final String NODE_SYMBOL = "node";

    NodeTypeEnum(String name, Class clazz) {
        this.name = name;
        this.clazz = clazz;
    }

    private String name;

    private Class<? extends NodeTemplateParse> clazz;

    public String getName() {
        return name;
    }

    public static Class<? extends NodeTemplateParse> getClass(String name) {
        NodeTypeEnum[] values = NodeTypeEnum.values();
        for (NodeTypeEnum value : values) {
            if (value.getName().equals(name)) {
                return value.clazz;
            }
        }
        throw new IllegalArgumentException(name + " is illegal");
    }
}
